#include "configwidget.h"
#include <stdio.h>
//!地图参数设置
MapParamWidget::MapParamWidget(QDialog *parent)
{
    m_Pos = {108, 54, 51, 34, 14, 7};//XDU
    m_distance = 15000;
    m_MapLongitudeLabel = new QLabel(tr("中心经度"), this);
    m_MapLatitudeLabel = new QLabel(tr("中心纬度"), this);
    m_MapDisLabel = new QLabel(tr("范围半径"), this);

    //纬度
    m_MapLatLabel_Degree = new QLabel(tr("°"), this);
    m_MapLatLabel_Minute = new QLabel(tr("′"), this);
    m_MapLatLabel_Second = new QLabel(tr("″"), this);

    m_MapLatEdit_Degree = new QSpinBox(this);
    m_MapLatEdit_Degree->setRange(-90, 90);
    m_MapLatEdit_Degree->setSingleStep(1);
    m_MapLatEdit_Degree->setValue(m_Pos.Lat_Degree);
    m_MapLatEdit_Degree->setWrapping(true);

    m_MapLatEdit_Minute = new QSpinBox(this);
    m_MapLatEdit_Minute->setRange(0, 59);
    m_MapLatEdit_Minute->setSingleStep(1);
    m_MapLatEdit_Minute->setValue(m_Pos.Lat_Minute);
    m_MapLatEdit_Minute->setWrapping(true);

    m_MapLatEdit_Second = new QSpinBox(this);
    m_MapLatEdit_Second->setRange(0, 59);
    m_MapLatEdit_Second->setSingleStep(1);
    m_MapLatEdit_Second->setValue(m_Pos.Lat_Second);
    m_MapLatEdit_Second->setWrapping(true);

    //经度
    m_MapLonLabel_Degree = new QLabel(tr("°"), this);
    m_MapLonLabel_Minute = new QLabel(tr("′"), this);
    m_MapLonLabel_Second = new QLabel(tr("″"), this);

    m_MapLonEdit_Degree = new QSpinBox(this);
    m_MapLonEdit_Degree->setRange(-180, 180);
    m_MapLonEdit_Degree->setSingleStep(1);
    m_MapLonEdit_Degree->setValue(m_Pos.Lon_Degree);
    m_MapLonEdit_Degree->setWrapping(true);

    m_MapLonEdit_Minute = new QSpinBox(this);
    m_MapLonEdit_Minute->setRange(0, 59);
    m_MapLonEdit_Minute->setSingleStep(1);
    m_MapLonEdit_Minute->setValue(m_Pos.Lon_Minute);
    m_MapLonEdit_Minute->setWrapping(true);

    m_MapLonEdit_Second = new QSpinBox(this);
    m_MapLonEdit_Second->setRange(0, 59);
    m_MapLonEdit_Second->setSingleStep(1);
    m_MapLonEdit_Second->setValue(m_Pos.Lon_Second);
    m_MapLonEdit_Second->setWrapping(true);

    //距离
    m_MapDisEdit = new QLineEdit(QString("%1").arg(m_distance),this);
    m_MapDisEdit->setAlignment(Qt::AlignCenter);

    OKButton = new QPushButton(this);
    OKButton->setText(tr("确定"));
    CancelButton = new QPushButton(this);
    CancelButton->setText(tr("取消"));

    QVBoxLayout m_leftLayout;
    m_leftLayout.addWidget(m_MapLongitudeLabel);
    m_leftLayout.addWidget(m_MapLatitudeLabel);
    m_leftLayout.addWidget(m_MapDisLabel);

    QGridLayout m_rightLayout;
    m_rightLayout.addWidget(m_MapLonEdit_Degree, 0, 0, 1, 1, Qt::AlignCenter);
    m_rightLayout.addWidget(m_MapLonLabel_Degree, 0, 1, 1, 1, Qt::AlignCenter);
    m_rightLayout.addWidget(m_MapLonEdit_Minute, 0, 2, 1, 1, Qt::AlignCenter);
    m_rightLayout.addWidget(m_MapLonLabel_Minute, 0, 3, 1, 1, Qt::AlignCenter);
    m_rightLayout.addWidget(m_MapLonEdit_Second, 0, 4, 1, 1, Qt::AlignCenter);
    m_rightLayout.addWidget(m_MapLonLabel_Second, 0, 5, 1, 1, Qt::AlignCenter);

    m_rightLayout.addWidget(m_MapLatEdit_Degree, 1, 0, 1, 1, Qt::AlignCenter);
    m_rightLayout.addWidget(m_MapLatLabel_Degree, 1, 1, 1, 1, Qt::AlignCenter);
    m_rightLayout.addWidget(m_MapLatEdit_Minute, 1, 2, 1, 1, Qt::AlignCenter);
    m_rightLayout.addWidget(m_MapLatLabel_Minute, 1, 3, 1, 1, Qt::AlignCenter);
    m_rightLayout.addWidget(m_MapLatEdit_Second, 1, 4, 1, 1, Qt::AlignCenter);
    m_rightLayout.addWidget(m_MapLatLabel_Second, 1, 5, 1, 1, Qt::AlignCenter);
    m_rightLayout.addWidget(m_MapDisEdit,2,0,1,6,Qt::AlignCenter);

    QHBoxLayout groupLayout;
    groupLayout.addLayout(&m_leftLayout);
    groupLayout.addLayout(&m_rightLayout);
    QHBoxLayout bottomLayout;
    bottomLayout.addWidget(OKButton);
    bottomLayout.addStretch();
    bottomLayout.addWidget(CancelButton);

    mainLayout = new QVBoxLayout;
    mainLayout->addLayout(&groupLayout);
    mainLayout->addLayout(&bottomLayout);

    setLayout(mainLayout);
    setWindowTitle(tr("地图参数配置窗口"));

    connect(OKButton, SIGNAL(clicked()), this, SLOT(getMapParameter()));
    connect(CancelButton, SIGNAL(clicked(bool)), this, SLOT(close()));
}

MapParamWidget::MapParamWidget(dvec2 LonLat, float distance, QDialog *parent):m_LonLat(LonLat), m_distance(distance)
{
    m_Pos = transferLattoDMS(m_LonLat);
    m_MapLongitudeLabel = new QLabel(tr("中心经度"), this);
    m_MapLatitudeLabel = new QLabel(tr("中心纬度"), this);
    m_MapDisLabel = new QLabel(tr("范围半径"), this);

    //纬度
    m_MapLatLabel_Degree = new QLabel(tr("°"), this);
    m_MapLatLabel_Minute = new QLabel(tr("′"), this);
    m_MapLatLabel_Second = new QLabel(tr("″"), this);

    m_MapLatEdit_Degree = new QSpinBox(this);
    m_MapLatEdit_Degree->setRange(-90, 90);
    m_MapLatEdit_Degree->setSingleStep(1);
    m_MapLatEdit_Degree->setValue(m_Pos.Lat_Degree);
    m_MapLatEdit_Degree->setWrapping(true);

    m_MapLatEdit_Minute = new QSpinBox(this);
    m_MapLatEdit_Minute->setRange(0, 59);
    m_MapLatEdit_Minute->setSingleStep(1);
    m_MapLatEdit_Minute->setValue(m_Pos.Lat_Minute);
    m_MapLatEdit_Minute->setWrapping(true);

    m_MapLatEdit_Second = new QSpinBox(this);
    m_MapLatEdit_Second->setRange(0, 59);
    m_MapLatEdit_Second->setSingleStep(1);
    m_MapLatEdit_Second->setValue(m_Pos.Lat_Second);
    m_MapLatEdit_Second->setWrapping(true);

    //经度
    m_MapLonLabel_Degree = new QLabel(tr("°"), this);
    m_MapLonLabel_Minute = new QLabel(tr("′"), this);
    m_MapLonLabel_Second = new QLabel(tr("″"), this);

    m_MapLonEdit_Degree = new QSpinBox(this);
    m_MapLonEdit_Degree->setRange(-180, 180);
    m_MapLonEdit_Degree->setSingleStep(1);
    m_MapLonEdit_Degree->setValue(m_Pos.Lon_Degree);
    m_MapLonEdit_Degree->setWrapping(true);

    m_MapLonEdit_Minute = new QSpinBox(this);
    m_MapLonEdit_Minute->setRange(0, 59);
    m_MapLonEdit_Minute->setSingleStep(1);
    m_MapLonEdit_Minute->setValue(m_Pos.Lon_Minute);
    m_MapLonEdit_Minute->setWrapping(true);

    m_MapLonEdit_Second = new QSpinBox(this);
    m_MapLonEdit_Second->setRange(0, 59);
    m_MapLonEdit_Second->setSingleStep(1);
    m_MapLonEdit_Second->setValue(m_Pos.Lon_Second);
    m_MapLonEdit_Second->setWrapping(true);

    //距离
    m_MapDisEdit = new QLineEdit(QString("%1").arg(m_distance),this);
    m_MapDisEdit->setAlignment(Qt::AlignCenter);

    OKButton = new QPushButton(this);
    OKButton->setText(tr("确定"));
    CancelButton = new QPushButton(this);
    CancelButton->setText(tr("取消"));

    QVBoxLayout *m_leftLayout = new QVBoxLayout;
    m_leftLayout->addWidget(m_MapLongitudeLabel);
    m_leftLayout->addWidget(m_MapLatitudeLabel);
    m_leftLayout->addWidget(m_MapDisLabel);

    QGridLayout *m_rightLayout = new QGridLayout;
    m_rightLayout->addWidget(m_MapLonEdit_Degree,  0, 0, 1, 1, Qt::AlignCenter);
    m_rightLayout->addWidget(m_MapLonLabel_Degree, 0, 1, 1, 1, Qt::AlignCenter);
    m_rightLayout->addWidget(m_MapLonEdit_Minute,  0, 2, 1, 1, Qt::AlignCenter);
    m_rightLayout->addWidget(m_MapLonLabel_Minute, 0, 3, 1, 1, Qt::AlignCenter);
    m_rightLayout->addWidget(m_MapLonEdit_Second,  0, 4, 1, 1, Qt::AlignCenter);
    m_rightLayout->addWidget(m_MapLonLabel_Second, 0, 5, 1, 1, Qt::AlignCenter);

    m_rightLayout->addWidget(m_MapLatEdit_Degree,  1, 0, 1, 1, Qt::AlignCenter);
    m_rightLayout->addWidget(m_MapLatLabel_Degree, 1, 1, 1, 1, Qt::AlignCenter);
    m_rightLayout->addWidget(m_MapLatEdit_Minute,  1, 2, 1, 1, Qt::AlignCenter);
    m_rightLayout->addWidget(m_MapLatLabel_Minute, 1, 3, 1, 1, Qt::AlignCenter);
    m_rightLayout->addWidget(m_MapLatEdit_Second,  1, 4, 1, 1, Qt::AlignCenter);
    m_rightLayout->addWidget(m_MapLatLabel_Second, 1, 5, 1, 1, Qt::AlignCenter);
    m_rightLayout->addWidget(m_MapDisEdit,2,0,1,6,Qt::AlignCenter);

    QHBoxLayout *groupLayout = new QHBoxLayout;
    groupLayout->addLayout(m_leftLayout);
    groupLayout->addLayout(m_rightLayout);
    QHBoxLayout *bottomLayout = new QHBoxLayout;
    bottomLayout->addWidget(OKButton);
    bottomLayout->addStretch();
    bottomLayout->addWidget(CancelButton);

    mainLayout = new QVBoxLayout;
    mainLayout->addLayout(groupLayout);
    mainLayout->addLayout(bottomLayout);

    setLayout(mainLayout);
    setWindowTitle(tr("地图参数配置窗口"));

    connect(OKButton, SIGNAL(clicked()), this, SLOT(getMapParameter()));
    connect(CancelButton, SIGNAL(clicked(bool)), this, SLOT(close()));
}

MapParamWidget::~MapParamWidget()
{

}

void MapParamWidget::getMapParameter()
{
    QString str;
    Position Pos;
    str = m_MapLonEdit_Degree->text();
    Pos.Lon_Degree = str.toInt();
    str = m_MapLonEdit_Minute->text();
    Pos.Lon_Minute = str.toInt();
    str = m_MapLonEdit_Second->text();
    Pos.Lon_Second = str.toInt();
    str = m_MapLatEdit_Degree->text();
    Pos.Lat_Degree = str.toInt();
    str = m_MapLatEdit_Minute->text();
    Pos.Lat_Minute = str.toInt();
    str = m_MapLatEdit_Second->text();
    Pos.Lat_Second = str.toInt();
    m_LonLat = transferDMStoLonLat(Pos);

    str = m_MapDisEdit->text();//距离
    m_distance = str.toFloat();
    emit emitMapParameter(m_LonLat, m_distance);   //发送至窗口控件类，计算雷达窗口位置及显示。
    this->close();
}

void MapParamWidget::setMapParameter(dvec2 CenLonLat, float fDistance)
{
    m_Pos = transferLattoDMS(CenLonLat);
    m_distance = fDistance;
    m_MapLonEdit_Degree->setValue(m_Pos.Lon_Degree);
    m_MapLonEdit_Minute->setValue(m_Pos.Lon_Minute);
    m_MapLonEdit_Second->setValue(m_Pos.Lon_Second);
    m_MapLatEdit_Degree->setValue(m_Pos.Lat_Degree);
    m_MapLatEdit_Minute->setValue(m_Pos.Lat_Minute);
    m_MapLatEdit_Second->setValue(m_Pos.Lat_Second);
    m_MapDisEdit->setText(QString::number(m_distance));
}

dvec2 MapParamWidget::transferDMStoLonLat(const Position &Pos)
{
    dvec2 LonLat;
    LonLat.x = (float)(Pos.Lon_Degree + Pos.Lon_Minute *1.0/60.0 +  Pos.Lon_Second *1.0/60.0/60.0);
    LonLat.y = (float)(Pos.Lat_Degree + Pos.Lat_Minute *1.0/60.0 +  Pos.Lat_Second *1.0/60.0/60.0);
    return LonLat;
}

Position MapParamWidget::transferLattoDMS(const dvec2 &LonLat)
{
    Position pos_rtn;
    pos_rtn.Lon_Degree = (int)LonLat.x;
    pos_rtn.Lon_Minute = (int)((LonLat.x-pos_rtn.Lon_Degree)*60);
    pos_rtn.Lon_Second = (int)((LonLat.x - pos_rtn.Lon_Degree - pos_rtn.Lon_Minute*1.0/60.0)*3600.0);
    pos_rtn.Lat_Degree = (int)LonLat.y;
    pos_rtn.Lat_Minute = (int)((LonLat.y-pos_rtn.Lat_Degree)*60);
    pos_rtn.Lat_Second = (int)((LonLat.y - pos_rtn.Lat_Degree - pos_rtn.Lat_Minute*1.0/60.0)*3600.0);
    return pos_rtn;
}

//!雷达参数设置
RadarParamWidget::RadarParamWidget(dvec2 Location, float DetectionDistance, float DirectionAngle, float StartAngle, float EndAngle, QDialog *parent)
    :QDialog(parent)
{
    m_RadarInfo.PosLonLat = Location;
    m_RadarInfo.fRadarDetectionDistance = DetectionDistance;
    m_RadarInfo.fDirectionAngle = DirectionAngle;
    m_RadarInfo.fStartAngle = StartAngle;
    m_RadarInfo.fEndAngle = EndAngle;
    m_Pos = transferLattoDMS(m_RadarInfo.PosLonLat);

    RadarLongitudeButton = new QPushButton(tr("雷达经度位置"), this);
    RadarLatitudeButton = new QPushButton(tr("雷达纬度位置"), this);
    DetectionRangeButton = new QPushButton(tr("雷达探测距离"), this);
    DirectionAngleButton = new QPushButton(tr("雷达法向角度"), this);
    StartAngleButton = new QPushButton(tr("起始探测角度"), this);
    EndAngleButton = new QPushButton(tr("终止探测角度"), this);

    RadarLonDegree_Label = new QLabel(tr("°"), this);
    RadarLonMinute_Label = new QLabel(tr("′"), this);
    RadarLonSecond_Label = new QLabel(tr("″"), this);
    RadarLatDegree_Label = new QLabel(tr("°"), this);
    RadarLatMinute_Label = new QLabel(tr("′"), this);
    RadarLatSecond_Label = new QLabel(tr("″"), this);

    RadarLonDegree_SpinBox = new QSpinBox(this);
    RadarLonDegree_SpinBox->setRange(-180, 180);
    RadarLonDegree_SpinBox->setSingleStep(1);
    RadarLonDegree_SpinBox->setValue(m_Pos.Lon_Degree);
    RadarLonDegree_SpinBox->setWrapping(true);

    RadarLonMinute_SpinBox = new QSpinBox(this);
    RadarLonMinute_SpinBox->setRange(0, 60);
    RadarLonMinute_SpinBox->setSingleStep(1);
    RadarLonMinute_SpinBox->setValue(m_Pos.Lon_Minute);
    RadarLonMinute_SpinBox->setWrapping(true);

    RadarLonSecond_SpinBox = new QSpinBox(this);
    RadarLonSecond_SpinBox->setRange(0, 60);
    RadarLonSecond_SpinBox->setSingleStep(1);
    RadarLonSecond_SpinBox->setValue(m_Pos.Lon_Second);
    RadarLonSecond_SpinBox->setWrapping(true);

    RadarLatDegree_SpinBox = new QSpinBox(this);
    RadarLatDegree_SpinBox->setRange(-90, 90);
    RadarLatDegree_SpinBox->setSingleStep(1);
    RadarLatDegree_SpinBox->setValue(m_Pos.Lat_Degree);
    RadarLatDegree_SpinBox->setWrapping(true);

    RadarLatMinute_SpinBox = new QSpinBox(this);
    RadarLatMinute_SpinBox->setRange(0, 60);
    RadarLatMinute_SpinBox->setSingleStep(1);
    RadarLatMinute_SpinBox->setValue(m_Pos.Lat_Minute);
    RadarLatMinute_SpinBox->setWrapping(true);

    RadarLatSecond_SpinBox = new QSpinBox(this);
    RadarLatSecond_SpinBox->setRange(0, 60);
    RadarLatSecond_SpinBox->setSingleStep(1);
    RadarLatSecond_SpinBox->setValue(m_Pos.Lat_Second);
    RadarLatSecond_SpinBox->setWrapping(true);

    QString input_str;
    input_str = QString::number(m_RadarInfo.fRadarDetectionDistance);
    DetectionRangeEdit = new QLineEdit(input_str);
    DetectionRangeEdit->setAlignment(Qt::AlignCenter);
    input_str = QString::number(m_RadarInfo.fDirectionAngle);
    DirectionAngleEdit = new QLineEdit(input_str);
    DirectionAngleEdit->setAlignment(Qt::AlignCenter);
    input_str = QString::number(m_RadarInfo.fStartAngle);
    StartAngleEdit = new QLineEdit(input_str);
    StartAngleEdit->setAlignment(Qt::AlignCenter);
    input_str = QString::number(m_RadarInfo.fEndAngle);
    EndAngleEdit = new QLineEdit(input_str);
    EndAngleEdit->setAlignment(Qt::AlignCenter);
    input_str.clear();

//    sendButton = new QToolButton;
//    sendButton->setText(tr("确定"));
//    sendButton->setCheckable(true);
//    sendButton->setChecked(false);

    leftLayout = new QVBoxLayout(this);
    leftLayout->addWidget(RadarLongitudeButton);
    leftLayout->addWidget(RadarLatitudeButton);
    leftLayout->addWidget(DetectionRangeButton);
    leftLayout->addWidget(DirectionAngleButton);
    leftLayout->addWidget(StartAngleButton);
    leftLayout->addWidget(EndAngleButton);

    QGridLayout rightLayout;
    rightLayout.addWidget(RadarLonDegree_SpinBox, 1, 0);
    rightLayout.addWidget(RadarLonDegree_Label, 1, 1);
    rightLayout.addWidget(RadarLonMinute_SpinBox, 1, 2);
    rightLayout.addWidget(RadarLonMinute_Label, 1, 3);
    rightLayout.addWidget(RadarLonSecond_SpinBox, 1, 4);
    rightLayout.addWidget(RadarLonSecond_Label, 1, 5);
    rightLayout.addWidget(RadarLatDegree_SpinBox, 2, 0);
    rightLayout.addWidget(RadarLatDegree_Label, 2, 1);
    rightLayout.addWidget(RadarLatMinute_SpinBox, 2, 2);
    rightLayout.addWidget(RadarLatMinute_Label, 2, 3);
    rightLayout.addWidget(RadarLatSecond_SpinBox, 2, 4);
    rightLayout.addWidget(RadarLatSecond_Label, 2, 5);
    rightLayout.addWidget(DetectionRangeEdit, 3, 0, 1, 6);
    rightLayout.addWidget(DirectionAngleEdit, 4, 0, 1, 6);
    rightLayout.addWidget(StartAngleEdit, 5, 0, 1, 6);
    rightLayout.addWidget(EndAngleEdit, 6, 0, 1, 6);

//    QHBoxLayout *groupLayout = new QHBoxLayout(this);
//    groupLayout->addLayout(&leftLayout);
//    groupLayout->addLayout(&rightLayout);

//    QHBoxLayout bottomLayout;
//    bottomLayout.addStretch();
//    bottomLayout.addWidget(sendButton);
//    bottomLayout.addStretch();

//    mainLayout = new QVBoxLayout(this);
//    mainLayout->addLayout(groupLayout);
//    mainLayout->addLayout(&bottomLayout);
//    setWindowTitle(tr("雷达参数配置窗口"));

    connect(sendButton, SIGNAL(clicked()), this, SLOT(getRadarParameter()));
    }

RadarParamWidget::RadarParamWidget(RadarParamInfoStruct RadarParamInfo, QDialog *parent):QDialog(parent)
{
    memcpy(&m_RadarInfo, &RadarParamInfo, sizeof(RadarParamInfoStruct));
    m_Pos = transferLattoDMS(m_RadarInfo.PosLonLat);

    RadarLongitudeButton = new QPushButton(tr("雷达经度位置"), this);
    RadarLatitudeButton = new QPushButton(tr("雷达纬度位置"), this);
    DetectionRangeButton = new QPushButton(tr("雷达探测距离"), this);
    DirectionAngleButton = new QPushButton(tr("雷达法向角度"), this);
    StartAngleButton = new QPushButton(tr("起始探测角度"), this);
    EndAngleButton = new QPushButton(tr("终止探测角度"), this);
    NorthOffsetButton = new QPushButton(tr("正北偏移"), this);

    RadarLonDegree_Label = new QLabel(tr("°"), this);
    RadarLonMinute_Label = new QLabel(tr("′"), this);
    RadarLonSecond_Label = new QLabel(tr("″"), this);
    RadarLatDegree_Label = new QLabel(tr("°"), this);
    RadarLatMinute_Label = new QLabel(tr("′"), this);
    RadarLatSecond_Label = new QLabel(tr("″"), this);

    RadarLonDegree_SpinBox = new QSpinBox(this);
    RadarLonDegree_SpinBox->setRange(-180, 180);
    RadarLonDegree_SpinBox->setSingleStep(1);
    RadarLonDegree_SpinBox->setValue(m_Pos.Lon_Degree);
    RadarLonDegree_SpinBox->setWrapping(true);

    RadarLonMinute_SpinBox = new QSpinBox(this);
    RadarLonMinute_SpinBox->setRange(0, 59);
    RadarLonMinute_SpinBox->setSingleStep(1);
    RadarLonMinute_SpinBox->setValue(m_Pos.Lon_Minute);
    RadarLonMinute_SpinBox->setWrapping(true);

    RadarLonSecond_SpinBox = new QSpinBox(this);
    RadarLonSecond_SpinBox->setRange(0, 59);
    RadarLonSecond_SpinBox->setSingleStep(1);
    RadarLonSecond_SpinBox->setValue(m_Pos.Lon_Second);
    RadarLonSecond_SpinBox->setWrapping(true);

    RadarLonError_SpinBox = new QSpinBox(this);
    RadarLonError_SpinBox->setRange(0,59);
    RadarLonError_SpinBox->setSingleStep(1);
    RadarLonError_SpinBox->setValue(m_Pos.Lon_Error);
    RadarLonError_SpinBox->setWrapping(true);


    RadarLatDegree_SpinBox = new QSpinBox(this);
    RadarLatDegree_SpinBox->setRange(-90, 90);
    RadarLatDegree_SpinBox->setSingleStep(1);
    RadarLatDegree_SpinBox->setValue(m_Pos.Lat_Degree);
    RadarLatDegree_SpinBox->setWrapping(true);

    RadarLatMinute_SpinBox = new QSpinBox(this);
    RadarLatMinute_SpinBox->setRange(0, 59);
    RadarLatMinute_SpinBox->setSingleStep(1);
    RadarLatMinute_SpinBox->setValue(m_Pos.Lat_Minute);
    RadarLatMinute_SpinBox->setWrapping(true);

    RadarLatSecond_SpinBox = new QSpinBox(this);
    RadarLatSecond_SpinBox->setRange(0, 59);
    RadarLatSecond_SpinBox->setSingleStep(1);
    RadarLatSecond_SpinBox->setValue(m_Pos.Lat_Second);
    RadarLatSecond_SpinBox->setWrapping(true);

    RadarLatError_SpinBox = new QSpinBox(this);
    RadarLatError_SpinBox->setRange(0, 59);
    RadarLatError_SpinBox->setSingleStep(1);
    RadarLatError_SpinBox->setValue(m_Pos.Lat_Error);
    RadarLatError_SpinBox->setWrapping(true);

    QString input_str;
    input_str = QString::number(m_RadarInfo.fRadarDetectionDistance);
    DetectionRangeEdit = new QLineEdit(input_str);
    DetectionRangeEdit->setAlignment(Qt::AlignCenter);
    input_str = QString::number(m_RadarInfo.fDirectionAngle);
    DirectionAngleEdit = new QLineEdit(input_str);
    DirectionAngleEdit->setAlignment(Qt::AlignCenter);
    input_str = QString::number(m_RadarInfo.fStartAngle);
    StartAngleEdit = new QLineEdit(input_str);
    StartAngleEdit->setAlignment(Qt::AlignCenter);
    input_str = QString::number(m_RadarInfo.fEndAngle);
    EndAngleEdit = new QLineEdit(input_str);
    EndAngleEdit->setAlignment(Qt::AlignCenter);
    input_str = QString::number(m_RadarInfo.fNorthOffset);
    NorthOffsetEdit = new QLineEdit(input_str);
    NorthOffsetEdit->setAlignment(Qt::AlignCenter);

    input_str.clear();

    sendButton = new QToolButton();
    sendButton->setText(tr("确定"));
    sendButton->setCheckable(true);
    sendButton->setChecked(false);

    leftLayout = new QVBoxLayout;
    leftLayout->addWidget(RadarLongitudeButton);
    leftLayout->addWidget(RadarLatitudeButton);
    leftLayout->addWidget(DetectionRangeButton);
    leftLayout->addWidget(DirectionAngleButton);
    leftLayout->addWidget(StartAngleButton);
    leftLayout->addWidget(EndAngleButton);
    leftLayout->addWidget(NorthOffsetButton);

    rightLayout = new QGridLayout;
    rightLayout->addWidget(RadarLonDegree_SpinBox, 1, 0);
    rightLayout->addWidget(RadarLonDegree_Label, 1, 1);
    rightLayout->addWidget(RadarLonMinute_SpinBox, 1, 2);
    rightLayout->addWidget(RadarLonMinute_Label, 1, 3);
    rightLayout->addWidget(RadarLonSecond_SpinBox, 1, 4);
    rightLayout->addWidget(RadarLonSecond_Label, 1, 5);
    rightLayout->addWidget(RadarLonError_SpinBox, 1, 6);
    rightLayout->addWidget(RadarLatDegree_SpinBox, 2, 0);
    rightLayout->addWidget(RadarLatDegree_Label, 2, 1);
    rightLayout->addWidget(RadarLatMinute_SpinBox, 2, 2);
    rightLayout->addWidget(RadarLatMinute_Label, 2, 3);
    rightLayout->addWidget(RadarLatSecond_SpinBox, 2, 4);
    rightLayout->addWidget(RadarLatSecond_Label, 2, 5);
    rightLayout->addWidget(RadarLatError_SpinBox, 2, 6);
    rightLayout->addWidget(DetectionRangeEdit, 3, 0, 1, 7);
    rightLayout->addWidget(DirectionAngleEdit, 4, 0, 1, 7);
    rightLayout->addWidget(StartAngleEdit, 5, 0, 1, 7);
    rightLayout->addWidget(EndAngleEdit, 6, 0, 1, 7);
    rightLayout->addWidget(NorthOffsetEdit, 7, 0, 1, 7);

    groupLayout = new QHBoxLayout;
    groupLayout->addLayout(leftLayout);
    groupLayout->addLayout(rightLayout);

    bottomLayout = new QHBoxLayout;
    bottomLayout->addStretch();
    bottomLayout->addWidget(sendButton);
    bottomLayout->addStretch();

    mainLayout = new QVBoxLayout(this);
    mainLayout->addLayout(groupLayout);
    mainLayout->addLayout(bottomLayout);
    setLayout(mainLayout);
    setWindowTitle(tr("雷达参数配置窗口"));

    connect(sendButton, SIGNAL(toggled(bool)), this, SLOT(getRadarParameter()));
}

RadarParamWidget::RadarParamWidget(Radar_Pos_Info_Param_t pRadarPosInfo, uint8_t RadarNum, QDialog *parent)
{
    m_RadarInfo.PosLonLat = pRadarPosInfo.LonLat;
    m_RadarInfo.fRadarDetectionDistance = pRadarPosInfo.fRadar_Detection_Distance;
    m_RadarInfo.fDirectionAngle = pRadarPosInfo.fDirection_Angle;
    m_RadarInfo.fStartAngle = pRadarPosInfo.fStart_Angle;
    m_RadarInfo.fEndAngle = pRadarPosInfo.fEnd_Angle;
    m_Pos = transferLattoDMS(m_RadarInfo.PosLonLat);

    RadarLongitudeButton = new QPushButton(tr("雷达经度位置"), this);
    RadarLatitudeButton = new QPushButton(tr("雷达纬度位置"), this);
    DetectionRangeButton = new QPushButton(tr("雷达探测距离"), this);
    DirectionAngleButton = new QPushButton(tr("雷达法向角度"), this);
    StartAngleButton = new QPushButton(tr("起始探测角度"), this);
    EndAngleButton = new QPushButton(tr("终止探测角度"), this);

    RadarLonDegree_Label = new QLabel(tr("°"), this);
    RadarLonMinute_Label = new QLabel(tr("′"), this);
    RadarLonSecond_Label = new QLabel(tr("″"), this);
    RadarLatDegree_Label = new QLabel(tr("°"), this);
    RadarLatMinute_Label = new QLabel(tr("′"), this);
    RadarLatSecond_Label = new QLabel(tr("″"), this);

    RadarLonDegree_SpinBox = new QSpinBox(this);
    RadarLonDegree_SpinBox->setRange(-180, 180);
    RadarLonDegree_SpinBox->setSingleStep(1);
    RadarLonDegree_SpinBox->setValue(m_Pos.Lon_Degree);
    RadarLonDegree_SpinBox->setWrapping(true);

    RadarLonMinute_SpinBox = new QSpinBox(this);
    RadarLonMinute_SpinBox->setRange(0, 60);
    RadarLonMinute_SpinBox->setSingleStep(1);
    RadarLonMinute_SpinBox->setValue(m_Pos.Lon_Minute);
    RadarLonMinute_SpinBox->setWrapping(true);

    RadarLonSecond_SpinBox = new QSpinBox(this);
    RadarLonSecond_SpinBox->setRange(0, 60);
    RadarLonSecond_SpinBox->setSingleStep(1);
    RadarLonSecond_SpinBox->setValue(m_Pos.Lon_Second);
    RadarLonSecond_SpinBox->setWrapping(true);

    RadarLatDegree_SpinBox = new QSpinBox(this);
    RadarLatDegree_SpinBox->setRange(-90, 90);
    RadarLatDegree_SpinBox->setSingleStep(1);
    RadarLatDegree_SpinBox->setValue(m_Pos.Lat_Degree);
    RadarLatDegree_SpinBox->setWrapping(true);

    RadarLatMinute_SpinBox = new QSpinBox(this);
    RadarLatMinute_SpinBox->setRange(0, 60);
    RadarLatMinute_SpinBox->setSingleStep(1);
    RadarLatMinute_SpinBox->setValue(m_Pos.Lat_Minute);
    RadarLatMinute_SpinBox->setWrapping(true);

    RadarLatSecond_SpinBox = new QSpinBox(this);
    RadarLatSecond_SpinBox->setRange(0, 60);
    RadarLatSecond_SpinBox->setSingleStep(1);
    RadarLatSecond_SpinBox->setValue(m_Pos.Lat_Second);
    RadarLatSecond_SpinBox->setWrapping(true);

    QString input_str;
    input_str = QString::number(m_RadarInfo.fRadarDetectionDistance);
    DetectionRangeEdit = new QLineEdit(input_str);
    DetectionRangeEdit->setAlignment(Qt::AlignCenter);
    input_str = QString::number(m_RadarInfo.fDirectionAngle);
    DirectionAngleEdit = new QLineEdit(input_str);
    DirectionAngleEdit->setAlignment(Qt::AlignCenter);
    input_str = QString::number(m_RadarInfo.fStartAngle);
    StartAngleEdit = new QLineEdit(input_str);
    StartAngleEdit->setAlignment(Qt::AlignCenter);
    input_str = QString::number(m_RadarInfo.fEndAngle);
    EndAngleEdit = new QLineEdit(input_str);
    EndAngleEdit->setAlignment(Qt::AlignCenter);
    input_str.clear();

    sendButton = new QToolButton();
    sendButton->setText(tr("确定"));
    sendButton->setCheckable(true);
    sendButton->setChecked(false);

    QVBoxLayout leftLayout;
    leftLayout.addWidget(RadarLongitudeButton);
    leftLayout.addWidget(RadarLatitudeButton);
    leftLayout.addWidget(DetectionRangeButton);
    leftLayout.addWidget(DirectionAngleButton);
    leftLayout.addWidget(StartAngleButton);
    leftLayout.addWidget(EndAngleButton);

    QGridLayout rightLayout;
    rightLayout.addWidget(RadarLonDegree_SpinBox, 1, 0);
    rightLayout.addWidget(RadarLonDegree_Label, 1, 1);
    rightLayout.addWidget(RadarLonMinute_SpinBox, 1, 2);
    rightLayout.addWidget(RadarLonMinute_Label, 1, 3);
    rightLayout.addWidget(RadarLonSecond_SpinBox, 1, 4);
    rightLayout.addWidget(RadarLonSecond_Label, 1, 5);
    rightLayout.addWidget(RadarLatDegree_SpinBox, 2, 0);
    rightLayout.addWidget(RadarLatDegree_Label, 2, 1);
    rightLayout.addWidget(RadarLatMinute_SpinBox, 2, 2);
    rightLayout.addWidget(RadarLatMinute_Label, 2, 3);
    rightLayout.addWidget(RadarLatSecond_SpinBox, 2, 4);
    rightLayout.addWidget(RadarLatSecond_Label, 2, 5);
    rightLayout.addWidget(DetectionRangeEdit, 3, 0, 1, 6);
    rightLayout.addWidget(DirectionAngleEdit, 4, 0, 1, 6);
    rightLayout.addWidget(StartAngleEdit, 5, 0, 1, 6);
    rightLayout.addWidget(EndAngleEdit, 6, 0, 1, 6);

    QHBoxLayout *groupLayout = new QHBoxLayout;
    groupLayout->addLayout(&leftLayout);
    groupLayout->addLayout(&rightLayout);

    QHBoxLayout bottomLayout;
    bottomLayout.addStretch();
    bottomLayout.addWidget(sendButton);
    bottomLayout.addStretch();

    mainLayout = new QVBoxLayout();
    mainLayout->addLayout(groupLayout);
    mainLayout->addLayout(&bottomLayout);
    setWindowTitle(tr("雷达参数配置窗口"));
    setLayout(mainLayout);

    connect(sendButton, SIGNAL(toggled()), this, SLOT(getRadarParameter()));

}

RadarParamWidget::~RadarParamWidget()
{
    #if 0
    while(leftLayout!=NULL)
        delete leftLayout;
    while(rightLayout != NULL)
        delete rightLayout;
    while(groupLayout != NULL)
        delete groupLayout;
    while(bottomLayout != NULL)
        delete bottomLayout;
    #endif
}

void RadarParamWidget::getRadarParameter()
{
    m_Pos = {RadarLonDegree_SpinBox->value(), RadarLonMinute_SpinBox->value(), RadarLonSecond_SpinBox->value(),RadarLonError_SpinBox->value(),
             RadarLatDegree_SpinBox->value(), RadarLatMinute_SpinBox->value(), RadarLatSecond_SpinBox->value(), RadarLatError_SpinBox->value()};
    m_RadarInfo.PosLonLat = transferDMStoLonLat(m_Pos);
    m_RadarInfo.fRadarDetectionDistance = DetectionRangeEdit->text().toFloat();
    m_RadarInfo.fDirectionAngle = DirectionAngleEdit->text().toFloat();
    m_RadarInfo.fStartAngle = StartAngleEdit->text().toFloat();
    m_RadarInfo.fEndAngle = EndAngleEdit->text().toFloat();
    m_RadarInfo.fNorthOffset = NorthOffsetEdit->text().toFloat();
    //emit emitRadarParameter(m_RadarInfo);
    emit emitRadarParameter(m_RadarInfo.PosLonLat, m_RadarInfo.fRadarDetectionDistance, m_RadarInfo.fDirectionAngle,
                            m_RadarInfo.fStartAngle, m_RadarInfo.fEndAngle, m_RadarInfo.fNorthOffset);

    this->close();
}

void RadarParamWidget::setRadarParameter(RadarParamInfoStruct info)
{
    memcpy(&m_RadarInfo, &info, sizeof(RadarParamInfoStruct));
    m_Pos = transferLattoDMS(m_RadarInfo.PosLonLat);
    RadarLonDegree_SpinBox->setValue(m_Pos.Lon_Degree);
    RadarLonDegree_SpinBox->setValue(m_Pos.Lon_Minute);
    RadarLonDegree_SpinBox->setValue(m_Pos.Lon_Second);
    RadarLatDegree_SpinBox->setValue(m_Pos.Lat_Degree);
    RadarLatDegree_SpinBox->setValue(m_Pos.Lat_Minute);
    RadarLatDegree_SpinBox->setValue(m_Pos.Lat_Second);
    DetectionRangeEdit->setText(QString::number(m_RadarInfo.fRadarDetectionDistance));
    DirectionAngleEdit->setText(QString::number(m_RadarInfo.fDirectionAngle));
    StartAngleEdit->setText(QString::number(m_RadarInfo.fStartAngle));
    EndAngleEdit->setText(QString::number(m_RadarInfo.fEndAngle));
}

dvec2 RadarParamWidget::transferDMStoLonLat(const Position &Pos)
{
    dvec2 LonLat;
    LonLat.x = (float)(Pos.Lon_Degree + Pos.Lon_Minute *1.0/60.0 +  Pos.Lon_Second *1.0/60.0/60.0 + Pos.Lon_Error *1.0/60.0/60.0/60.0);
    LonLat.y = (float)(Pos.Lat_Degree + Pos.Lat_Minute *1.0/60.0 +  Pos.Lat_Second *1.0/60.0/60.0 + Pos.Lat_Error *1.0/60.0/60.0/60.0);
    return LonLat;
}

Position RadarParamWidget::transferLattoDMS(const dvec2 &LonLat)
{
    Position pos_rtn;
    pos_rtn.Lon_Degree = (int)LonLat.x;
    pos_rtn.Lon_Minute = (int)((LonLat.x - pos_rtn.Lon_Degree)*60);
    pos_rtn.Lon_Second = (int)((LonLat.x - pos_rtn.Lon_Degree - pos_rtn.Lon_Minute*1.0f/60.0)*3600.0);
    pos_rtn.Lon_Error  = (int)((LonLat.x - pos_rtn.Lon_Degree - pos_rtn.Lon_Minute*1.0f/60.0 - pos_rtn.Lon_Second/3600.0f)*60.0*60.0*60.0);
    pos_rtn.Lat_Degree = (int)LonLat.y;
    pos_rtn.Lat_Minute = (int)((LonLat.y-pos_rtn.Lat_Degree)*60);
    pos_rtn.Lat_Second = (int)((LonLat.y - pos_rtn.Lat_Degree - pos_rtn.Lat_Minute*1.0/60.0)*3600.0);
    pos_rtn.Lat_Error  = (int)((LonLat.y - pos_rtn.Lat_Degree - pos_rtn.Lat_Minute*1.0f/60.0 - pos_rtn.Lat_Second/3600.0f)*60.0*60.0*60.0);

    return pos_rtn;
}

//!雷达航迹设置
TrackerController::TrackerController(QWidget *parent):QWidget(parent)
{
    m_infostr.color = Qt::black;
    m_infostr.ID_tobeDeleted = 0;
    m_infostr.ID_tobesaved = 0;
    m_infostr.fspeed_max = 500;
    m_infostr.fspeed_min = -500;
    m_infostr.ID_todyeing = 0;

    saveTrack_Label = new QLabel(tr("确定航迹/ID"), this);
    deleteTracker_Label = new QLabel(tr("删除航迹/ID"), this);
    saveTrack_Edit = new QLineEdit(QString("%1").arg(m_infostr.ID_tobesaved), this);
    deleteTrack_Edit = new QLineEdit(QString("%1").arg(m_infostr.ID_tobeDeleted), this);

    TrackerManager_GroupBox = new QGroupBox(tr("航迹管理"), this);
    manager_Layout = new QGridLayout(TrackerManager_GroupBox);
    manager_Layout->addWidget(saveTrack_Label, 0, 0, 1, 1, Qt::AlignCenter);
    manager_Layout->addWidget(saveTrack_Edit, 0, 1, 1, 3, Qt::AlignCenter);
    manager_Layout->addWidget(deleteTracker_Label, 1, 0, 1, 1, Qt::AlignCenter);
    manager_Layout->addWidget(deleteTrack_Edit, 1, 1, 1, 3, Qt::AlignCenter);

    dyeingTracker_Label = new QLabel(tr("航迹着色    ID"), this);
    selectSpeed_Label = new QLabel(tr("速度选择"), this);
    SpeedRangeMax_Label = new QLabel(tr("最小值"), this);
    SpeedRangeMin_Label = new QLabel(tr("最大值"), this);
    dyeingTracker_Edit = new QLineEdit(QString("%1").arg(m_infostr.ID_todyeing), this);
    SpeedMin_SpinBox = new QSpinBox(this);
    SpeedMin_SpinBox->setRange(SPEED_MIN, SPEED_MAX);
    SpeedMin_SpinBox->setSingleStep(1);
    SpeedMin_SpinBox->setValue(SPEED_MIN);
    SpeedMin_SpinBox->setWrapping(true);
    SpeedMax_SpinBox = new QSpinBox(this);
    SpeedMax_SpinBox->setRange(SPEED_MIN, SPEED_MAX);
    SpeedMax_SpinBox->setSingleStep(1);
    SpeedMax_SpinBox->setValue(SPEED_MAX);
    SpeedMax_SpinBox->setWrapping(true);
    color_Combox = new QComboBox(this);
    fillColorList(color_Combox);
    color_Combox->setCurrentIndex(7);//black

    TrackSetting_GroupBox = new QGroupBox(tr("航迹设置"), this);
    setting_Layout = new QGridLayout(TrackSetting_GroupBox);
    for(int i=0; i<5; i++)
        setting_Layout->setColumnStretch(i, 1);
    setting_Layout->addWidget(selectSpeed_Label, 0, 0, 1, 1, Qt::AlignCenter);
    setting_Layout->addWidget(SpeedRangeMin_Label, 0, 1, 1, 1, Qt::AlignCenter);
    setting_Layout->addWidget(SpeedMin_SpinBox, 0, 2, 1, 1, Qt::AlignCenter);
    setting_Layout->addWidget(SpeedRangeMax_Label, 0, 3, 1, 1, Qt::AlignCenter);
    setting_Layout->addWidget(SpeedMax_SpinBox, 0, 4, 1, 1, Qt::AlignCenter);
    setting_Layout->addWidget(dyeingTracker_Label, 1, 0, 1, 2, Qt::AlignLeft);
    setting_Layout->addWidget(dyeingTracker_Edit, 1, 2, 1, 1, Qt::AlignCenter);
    setting_Layout->addWidget(color_Combox, 1, 3, 1, 2, Qt::AlignLeft);

    sendButton = new QToolButton(this);
    sendButton->setText(tr("发送"));
    cancelButton = new QToolButton(this);
    cancelButton->setText(tr("取消"));
    buttongroup_Layout = new QHBoxLayout;
    buttongroup_Layout->addStretch();
    buttongroup_Layout->addWidget(sendButton);
    buttongroup_Layout->addStretch();
    buttongroup_Layout->addWidget(cancelButton);
    buttongroup_Layout->addStretch();

    mainlayout = new QVBoxLayout(this);

    mainlayout->addWidget(TrackerManager_GroupBox);
    mainlayout->addWidget(TrackSetting_GroupBox);
    mainlayout->addLayout(buttongroup_Layout);

    setLayout(mainlayout);
    setFixedSize(300, 260);
    connect(sendButton, SIGNAL(clicked(bool)), this, SLOT(getTrackerCrtlInfo()));
    connect(cancelButton, SIGNAL(clicked(bool)), this, SLOT(close()));
}

TrackerController::~TrackerController()
{
    while(buttongroup_Layout !=NULL)
        delete buttongroup_Layout;
}

void TrackerController::fillColorList(QComboBox *ComboBox)
{
    colorNameList = QColor::colorNames();
    QString colorName;
    foreach(colorName,colorNameList)
    {
        QPixmap pix_color(QSize(70,15));
        pix_color.fill(QColor(colorName));

        ComboBox->addItem(QIcon(pix_color),NULL);
        ComboBox->setIconSize(QSize(70,15));
        ComboBox->setSizeAdjustPolicy(QComboBox::AdjustToContents);   //设置下拉列表的尺寸符合内容的大小
    }
}

void TrackerController::getTrackerCrtlInfo()
{
    m_infostr.ID_tobesaved = saveTrack_Edit->text().toInt();
    m_infostr.ID_tobeDeleted = deleteTrack_Edit->text().toInt();
    m_infostr.ID_todyeing = deleteTrack_Edit->text().toInt();
    m_infostr.color = QColor(QColor::colorNames().at(color_Combox->currentIndex()));
    m_infostr.fspeed_min = SpeedMin_SpinBox->value();
    m_infostr.fspeed_max = SpeedMax_SpinBox->value();

    emit emitTrackerCrtlInfo(m_infostr);
    close();
}























